#include "include.h"
// takes Irrlicht device and video driver
Graphics::Graphics(irr::IrrlichtDevice* videoDeviceReference, irr::video::IVideoDriver* videoDriverReference)
{
      videoDevice = videoDeviceReference;
      videoDriver = videoDriverReference;
      frameDuration = 0;
      currentFrame = 0;
}
// draws static sprites
// pointer to frame container, x coordinate, y coordinate, animation frame (does nothing currently, always use 0)
void Graphics::draw(std::vector<FrameContainer*>* frameVector, int xCoord, int yCoord, int animationFrame)
{
     videoDriver->draw2DImage(videoDriver->getTexture(
        frameVector->at(animationFrame)->fileName.c_str()),irr::core::position2d<irr::s32>(xCoord,yCoord),
        irr::core::rect<irr::s32>(0,0,frameVector->at(animationFrame)->width,
        frameVector->at(animationFrame)->height), 0, irr::video::SColor(255,255,255,255), true);
}
// draws animated sprites
// pointer to frame container, x coordinate, y coordinate, amount of time to display frame in 1/10 second
void Graphics::draw(std::vector<FrameContainer*>* frameVector, int xCoord, int yCoord, irr::u32 currentTime)
{

    irr::video::ITexture* currentTexture;

    if (currentTime > frameDuration)
    {
        currentFrame++;
        if (currentFrame > frameVector->size())
        {
            currentFrame = 1;
        }
        frameDuration = currentTime + (frameVector->at(currentFrame - 1)->duration * 10);
        currentFrameFile = frameVector->at(currentFrame - 1)->fileName;
    }

    currentTexture = videoDriver->getTexture(currentFrameFile.c_str());
    videoDriver->draw2DImage(currentTexture, irr::core::position2d<irr::s32>(xCoord,yCoord),
        irr::core::rect<irr::s32>(0,0,frameVector->at(currentFrame - 1)->width,
        frameVector->at(currentFrame - 1)->height), 0, irr::video::SColor(255,255,255,255), true);
}
// gets height of game window
int Graphics::getScreenHeight()
{
    return videoDevice->getVideoDriver()->getScreenSize().Height;
}
// gets width of game window
int Graphics::getScreenWidth()
{
    return videoDevice->getVideoDriver()->getScreenSize().Width;
}
